package com.xhui.vimarket.zkplus.zul.attr.mod.impl;
import java.util.List;
import java.util.Map;

import org.directwebremoting.util.Logger;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Div;
import com.xhui.vimarket.zkpcom.xhui.vimarket.zkplusan.AttrInst;
import com.xhui.vimcom.xhui.vimarket.zkplusl.attr.bean.AttrTmpl;
import com.xhui.vimarket.zkplus.zul.attr.util.Attcom.xhui.vimarket.zkplus/**
 * @版权：福富软件 版权所有 (c) 2010
 * @文件：com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrTextComp.java
 * @所含类：
 * @author: wuyx
 * @version: V1.0
 * @see:
 * @创建日期：2010-12-20
 * @功能说明：属性控件接口
 * @修改记录： =============================================================<br>
 *        日期:2010-12-20 创建
 *        =============================================================<br>
 */
public class AttrDivExtComp extends AttrBaseComp {
    
    /**
     * DIV_DEF_COMPOSER.
com.xhui.vimarket.zkplusblic static final String    DIV_DEF_COMPOSER = "com.xhui.vimarket.zkplus.zul.attr.evt.AttrDivExtDivComposer";
    
    /**
     * 实例.
     */
    private static AttrDivExtComp inst             = new AttrDivExtComp();
    
    /**
     * 日志.
     */
    private static Logger         logger           = Logger.getLogger(AttrDivExtComp.class);
   
    /**
     * 主数据参数2.
     */
    private String     param2url      = null;
    
    /**
     * 构造函数. 
     */
    protected AttrDivExtComp() {
    }
    
    /**
     * 获取实例.
     * 
     * @return AttrBaseComp
     */
    public static AttrDivExtComp instance() {
        return AttrDivExtComp.inst;
    }
    
    /**
     * 生成组件.
     * 
     * @param attrExt 组件控件
     * @param attrTmpl 组件模板
     * @param comp 显示容器组件
     */
    @SuppressWarnings("deprecation")
    @Override
    public void create(final AttrExt attrExt, final AttrTmpl attrTmpl, final Component comp) {
        super.create(attrExt, attrTmpl, comp);
        // div    
        //final String sDivWithComposer = attrExt.getAttrAda().getAttrTmplCompStr(
        //attrTmpl.getDisplayMode(), attrTmpl, attrTmpl.getParam2(), null, null);
        //final Div div = (Div) Executions.createComponentsDirectly(sDivWithComposer, null, comp,
        //null);
        
        //增加supDiv层   黄元强 2011-12-29
        final Div supDiv = new Div();
        supDiv.setAttribute(AttrBaseComp.COMP_MODE, attrTmpl.getDisplayMode());
        supDiv.setAttribute(AttrBaseComp.COMP_ATTRID, attrTmpl.getAttrId());
        supDiv.setAttribute(AttrBaseComp.COMP_COMPCODE, attrTmpl.getComponetCode());
        supDiv.setParent(comp);
        
        String url = null;
        if (attrTmpl.getParam2() != null) {
            if (attrTmpl.getParam2().contains("?")) {
                int index = attrTmpl.getParam2().indexOf("?");
                if (index != -1) {
                    url = attrTmpl.getParam2().substring((int) (index) + 1);
                    param2url = attrTmpl.getParam2().substring(0, index);
                }
            } else {
                param2url = attrTmpl.getParam2();
            }
        }else {
            param2url = null;
        }
        supDiv.setAttribute("param2url", url);
        if (!attrTmpl.isDisplay()
            || AttrConstants.DISPLAY_STYLE_PANEL_HIDE.equals(attrTmpl.getDisplayStyle())) {
            supDiv.setVisible(false); // 隐藏
        }
        final Div div = (Div) attrExt.getAttrAda().getAttrTmplCompStr(
            attrTmpl.getDisplayMode(), attrTmpl, param2url, null, null, supDiv);       
        div.setWidth("100%");
        // add to zul
        // comp log
        if (AttrDivExtComp.logger.isDebugEnabled()) {
            attrExt.appendInnerComp("<hbox width=\"100%\">");
            attrExt.appendInnerCompAttr(AttrBaseComp.COMP_MODE, attrTmpl.getDisplayMode());
            attrExt.appendInnerCompAttr(AttrBaseComp.COMP_ATTRID, "" + attrTmpl.getAttrId());
            attrExt.appendInnerComp("<label value=\"");
            attrExt.appendInnerComp(attrTmpl.getName());
            attrExt.appendInnerComp("\" />");
            attrExt.appendInnerComp("</hbox>");
        }
        if (attrExt.getAttrAda().isViewMode()) { // 展示模式
            ZkUiUtil.setDisabled(div, true);
        }
        
        super.afterCreate(attrExt, attrTmpl, comp);
    }
    
    /**
     * 设置值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @param attrInstList 属性实例
     *  @param attrViewMap 信息权限列表 控制框架的信息
     */
    @Override
    public void setValue(final AttrExt attrExt, final Component comp,
        final List<AttrInst> attrInstList, Map<String, Integer> attrViewMap) {
        super.setValue(attrExt, comp, attrInstList,attrViewMap);
    }
    
    /**
     * 获取值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @return ArrayList<AttrInst>
     */
    @Override
    public ArrayList<AttrInst> getValue(final AttrExt attrExt, final Component comp) {
        super.getValue(attrExt, comp);
        return null;
    }
    
    /**
     * 取空值属性实例.
     * 
     * @param attrExt 组件控件
     * @param attrTmpl 模板
     * @return ArrayList<AttrInst>
     */
    @Override
    public ArrayList<AttrInst> getNullValue(final AttrExt attrExt, final AttrTmpl attrTmpl) {
        super.getNullValue(attrExt, attrTmpl);
        return null;
    }
    
    /**
     * 清空值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     */
    @Override
    public void clean(final AttrExt attrExt, final Component comp) {
        super.clean(attrExt, comp);
    }
    
    /**
     * 设置为不允许修改.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @param tflag 设置值，true/false
     */
    @Override
    public void setDisabled(AttrExt attrExt, Component comp, boolean tflag) {
        super.setDisabled(attrExt, comp, tflag);
        ZkUiUtil.setDisabled(comp, tflag);
    }
    
}
